From 3cbd2f29166e25e98dddd2363d42a35e8306ac22 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Sat, 4 Mar 2006 23:29:46 +0000 Subject: [PATCH] (bug 5167) Add {{SUBPAGENAME}} variable --- RELEASE-NOTES | 1 + includes/MagicWord.php | 2 ++ includes/Parser.php | 2 ++ includes/Title.php | 14 ++++++++++++++ languages/Language.php | 1 + 5 files changed, 20 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index aa446dbcfb..425e405c91 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -277,6 +277,7 @@ Parser: * (bug 4783) : Fix for "{{ns:0}} does not render" * Improved support for interwiki transclusion * (bug 1850) Image link to nonexistent file fixed. +* (bug 5167) Add {{SUBPAGENAME}} variable Upload: * (bug 2527) Always set destination filename when new file is selected diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 9d0b3bf2fc..55edbc8e31 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -70,6 +70,7 @@ $magicWords = array( 'MAG_FULLPAGENAME', 'MAG_FULLPAGENAMEE', 'MAG_RAW', + 'MAG_SUBPAGENAME', ); if ( ! defined( 'MEDIAWIKI_INSTALL' ) ) wfRunHooks( 'MagicWordMagicWords', array( &$magicWords ) ); @@ -102,6 +103,7 @@ $wgVariableIDs = array( MAG_CURRENTWEEK, MAG_CURRENTDOW, MAG_REVISIONID, + MAG_SUBPAGENAME ); if ( ! defined( 'MEDIAWIKI_INSTALL' ) ) wfRunHooks( 'MagicWordwgVariableIDs', array( &$wgVariableIDs ) ); diff --git a/includes/Parser.php b/includes/Parser.php index 90b382a744..8165de79cf 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -2022,6 +2022,8 @@ class Parser return $this->mTitle->getPrefixedText(); case MAG_FULLPAGENAMEE: return $this->mTitle->getPrefixedURL(); + case MAG_SUBPAGENAME: + return $this->mTitle->getSubpageText(); case MAG_REVISIONID: return $this->mRevisionId; case MAG_NAMESPACE: diff --git a/includes/Title.php b/includes/Title.php index f2349bc0f5..3f276f610d 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -676,6 +676,20 @@ class Title { return $text; } + /** + * Get the lowest-level subpage name, i.e. the rightmost part after / + * @return string Subpage name + */ + function getSubpageText() { + global $wgNamespacesWithSubpages; + if( $wgNamespacesWithSubpages[ $this->mNamespace ] ) { + $parts = explode( '/', $this->mTextform ); + return( $parts[ count( $parts ) - 1 ] ); + } else { + return( $this->mTextform ); + } + } + /** * Get a URL-encoded title (not an actual URL) including interwiki * @return string the URL-encoded form diff --git a/languages/Language.php b/languages/Language.php index f152146965..aba1f93bc8 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -226,6 +226,7 @@ $wgLanguageNamesEn =& $wgLanguageNames; MAG_NAMESPACEE => array( 1, 'NAMESPACEE' ), MAG_FULLPAGENAME => array( 1, 'FULLPAGENAME' ), MAG_FULLPAGENAMEE => array( 1, 'FULLPAGENAMEE' ), + MAG_SUBPAGENAME => array( 0, 'SUBPAGENAME' ), MAG_MSG => array( 0, 'MSG:' ), MAG_SUBST => array( 0, 'SUBST:' ), MAG_MSGNW => array( 0, 'MSGNW:' ), -- 2.20.1